package com.voole.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.astuetz.viewpager.extensions.sample.R;
import com.voole.fragments.LocalAppFragment.AppInfo;

public class LocalAppAdapter extends ArrayAdapter<AppInfo> {

	public LocalAppAdapter(Context context, List<AppInfo> mlist) {
		super(context, 0,mlist);
	}
	
	@Override
	public View getView(int position, View mVm, ViewGroup parent) {
		final AppInfo mInfo = getItem(position);
		if(mVm==null){
			LayoutInflater in = LayoutInflater.from(getContext());
			mVm = in.inflate(R.layout.item_local_app, null);
			ViewTag mTag = new ViewTag();
			mTag.icon = (ImageView) mVm.findViewById(R.id.iv_app_icon);
			mTag.name = (TextView) mVm.findViewById(R.id.tv_app_name);
			mVm.setTag(mTag);
			mTag.icon.setImageDrawable(mInfo.getIcon());
			mTag.name.setText(mInfo.getName());
		}else{
			ViewTag mTag = (ViewTag) mVm.getTag();
			mTag.icon.setImageDrawable(mInfo.getIcon());
			mTag.name.setText(mInfo.getName());
		}
		return mVm;
	}
	private static class ViewTag{
		public ImageView icon;
		public TextView name;
	}

}
